package com.activity;

import android.app.Activity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ViewFlipper;

public class LaActivity extends Activity{
	private ViewFlipper lcpmt_a;
	private float startX;

	private Animation in_lefttoright;
	private Animation out_lefttoright;

	private Animation in_righttoleft;
	private Animation out_righttoleft;

//
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.lcpmt_a);
		lcpmt_a = (ViewFlipper) findViewById(R.id.lcpmt_a);

		in_lefttoright = AnimationUtils.loadAnimation(this,
				R.anim.enter_lefttoright);
		out_lefttoright = AnimationUtils.loadAnimation(this,
				R.anim.exit_lefttoright);

		in_righttoleft = AnimationUtils.loadAnimation(this,
				R.anim.enter_righttoleft);
		out_righttoleft = AnimationUtils.loadAnimation(this,
				R.anim.exit_righttoleft);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {

		if(event.getAction()==MotionEvent.ACTION_DOWN){

			startX = event.getX();
			
		}else if(event.getAction()==MotionEvent.ACTION_UP){
			
			float endX = event.getX();
			
			if (endX > startX) {
				
				lcpmt_a.setInAnimation(in_lefttoright);
				lcpmt_a.setOutAnimation(out_lefttoright);
				lcpmt_a.showNext(); // 显示下一页
				
			} else if (endX < startX) {
				
				lcpmt_a.setInAnimation(in_righttoleft);
				lcpmt_a.setOutAnimation(out_righttoleft);
				lcpmt_a.showPrevious(); // 显示前一页
				
				return true;
			}
			
		}
		return super.onTouchEvent(event);
	}
}